package com.enjoyor.soa.traffic.frame.logger.impl;

import java.util.Date;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.enjoyor.soa.traffic.frame.domain.PubLog;
import com.enjoyor.soa.traffic.frame.logger.IPubLogMapper;
import com.enjoyor.soa.traffic.frame.support.mybatis.mapper.impl.BaseMapper;
import com.enjoyor.soa.traffic.util.enums.log.LogInfoDic;

@Service
@Transactional
public class PubLogMapper extends BaseMapper<PubLog> implements IPubLogMapper {

    @Override
    public void insert(PubLog pubLog) {
        pubLog.setLogId(String.valueOf(System.nanoTime()));
        pubLog.setLogTime(new Date());
        super.insert(pubLog);
    }

    @Override
    public void saveNoramlLogInfo(String userName, String logSystem, String transType, String content, String modular) {
        PubLog pubLog = new PubLog();
        pubLog.setLogUser(userName);
        pubLog.setLogLevel(LogInfoDic.LOG_LEVEL_ENUM.LOG_NORMAL.getCode());
        pubLog.setLogLevelName(LogInfoDic.LOG_LEVEL_ENUM.LOG_NORMAL.getMessage());
        pubLog.setLogClass(LogInfoDic.LOG_CLASS_ENUM.OPERATOR.getCode());
        pubLog.setLogClassName(LogInfoDic.LOG_CLASS_ENUM.OPERATOR.getMessage());
        pubLog.setLogSystem(logSystem);
        pubLog.setTransType(transType);
        for (LogInfoDic.LOG_TRANSTYPE_ENUM e : LogInfoDic.LOG_TRANSTYPE_ENUM.values()) {
            if (e.getCode().equals(transType))
                pubLog.setTransTypeName(e.getMessage());
        }
        pubLog.setContent(content);
        pubLog.setLogModular(modular);
        this.insert(pubLog);
    }

}
